function checkRadioButton(value){
	if(value=="link"){
		show(link);
		hide(image);
		hide(video);
	} else if (value=="image"){
		hide(link);
		show(image);
		hide(video);
	} else if(value=="video"){
		hide(link);
		hide(image);
		show(video);
	}
}
		
function show(obj){
	var div = document.getElementById(obj);
	div.style.display = '';
}

function hide(obj){
	var div = document.getElementById(obj);
	div.style.display = 'none';
}


function getCheckedValue(radioObj) 
{
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function showPreview()
{
	
	var imagesrc = document.getElementById('image');
	var videosrc = document.getElementById('video');
	var linksrc = document.getElementById('link');
	var newimg = document.createElement('img');
	var newvideo = document.createElement('iframe');
	var newdiv = document.createElement('div');
	var newlink = document.createElement('link');
	var diviterator = document.getElementsByClassName('container');
	
//	alert(getCheckedValue(imagesrc)=="");
	var isnotimage = getCheckedValue(imagesrc)=="";
	var isnotvideo = getCheckedValue(videosrc)=="";
	var isnotlink = getCheckedValue(linksrc)=="";
	var newelement;
	if (!isnotimage)
	{
		newimg.setAttribute('src','content/1.jpg');
		newimg.setAttribute('width','400');
		newimg.setAttribute('height','300');
		newimg.setAttribute('class','preview');
		newelement = newimg;
	}
	if (!isnotvideo)
	{
		newvideo.setAttribute('src','http://www.youtube.com/embed/PY4d0FwB0wE');
		newvideo.setAttribute('width','400px');
		newvideo.setAttribute('height','300px');
		newvideo.setAttribute('class','preview');
		newvideo.setAttribute('frameborder','0');
		newelement = newvideo;
	}
	if (!isnotlink)
	{
		var newp = document.createElement('a');
		newp.setAttribute('class','linkpreview');
		newp.innerHTML = document.getElementById('linkURL').value;
		newp.setAttribute('href',document.getElementById('linkURL').value);

		newdiv.setAttribute('class','preview');
		newdiv.appendChild(newp);
		
		newp = document.createElement('p');
		newp.setAttribute('class','despreview');
		newp.innerHTML =document.getElementById('linkDesc').value;
		newdiv.appendChild(newp);
		newelement = newdiv;
	}
	
	if(!isclicked&&(!isnotimage||!isnotvideo||!isnotlink))
	{
		isclicked = 1;
		diviterator[0].appendChild(newelement);
	}
	else
	{
		diviterator[0].removeChild(document.getElementById('submitPost').nextSibling.nextSibling);
		diviterator[0].appendChild(newelement);
	}
	
}
